package offer;

/**
 * @author SSK
 * //丑数
 */
public class T34 {
    public int GetUglyNumber_Solution(int index) {
        if (index<7) {
            return index;
        }
        int number[] = new int[index+1];
        number[0]=1;
        int t1=0, t2 = 0, t3 = 0;
        for (int i = 1; i < index; i++) {
            number[i] = Math.min(number[t1]*2,Math.min(number[t2]*3,number[t3]*5));
            if (number[i]==number[t1]*2)  {
                t1++;
            }
            if (number[i]==number[t2]*3) {
                t2++;
            }
            if (number[i]==number[t3]*5) {
                t3++;
            }

        }
        return number[index-1];
    }
}
